package com.example.demo.controller;


import com.example.demo.config.Interceptor.PassToken;
import com.example.demo.dao.TokenDao;
import com.example.demo.dao.User;
import com.example.demo.service.impl.Userserviceimpl;
import com.example.demo.utils.CommonRetumType;
import com.example.demo.utils.JwtUtils;
import com.example.demo.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
public class textredis extends BaseController{

    private static int Expirettime=60;
    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    HttpSession httpSession;


    //redis缓存
    @GetMapping("/set")
    public boolean redisset(String key,String value)
    {
        User user=new User();
        user.setId(Integer.valueOf(1));
        user.setName("su");
        return redisUtil.set(key,value);
    }
    @RequestMapping("get")
    public Object redisget(String key){
        return redisUtil.get(key);
    }

    //token生成
    @PassToken
    @PostMapping("/logintest")
    public CommonRetumType login (@Validated String username, @Validated String password){
        Userserviceimpl userserviceimpl = new Userserviceimpl();
        User user = userserviceimpl.login(username, password);
//        String token = JwtUtils.createToken(user.getId().toString(),user.getRoleId().toString(),user.getUsername());
//        TokenDao tokenDao = new TokenDao();
//        tokenDao.setToken(token);
        return CommonRetumType.create(user);
    }

}
